package org.gap.jseed.annotation.validation;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import org.gap.jseed.util.AnnotationExtractor;

public class NullableHandler implements InvocationHandler {
	private Nullable myNullable; 
	
	@Override
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		if (myNullable == null) {
			myNullable = AnnotationExtractor.getAnnotation(proxy, method, Nullable.class);
		} 
		if (myNullable.value() == false) {
			if (args[0] == null)
				throw new NullPointerException();
		}
		
		return null;
	}
}
